var e = getApp(), t = require("../../utils/data.js");

Page({
    data: {
        motto: "",
        userInfo: {},
        hasUserInfo: !1,
        hiddenmodalput: !0,
        hiddenmodalput1: !0,
        canIUse: wx.canIUse("button.open-type.getUserInfo")
    },
    szqdDetail: function(e) {
        var a = this;
        wx.request({
            url: t.getInterfaceData() + "getphonenum.action",
            data: {
                stunum: wx.getStorageSync("person_uname")
            },
            header: {
                "content-type": "application/json"
            },
            success: function(e) {
                if (console.log(e.data), "error" == e.data) a.setData({
                    hiddenmodalput: !a.data.hiddenmodalput,
                    sjsvalue: ""
                }); else if ("" == wx.getStorageSync("personphone")) a.setData({
                    hiddenmodalput1: !a.data.hiddenmodalput1,
                    sjsvalue: ""
                }); else {
                    a.setData({
                        phone: e.data,
                        stunum: wx.getStorageSync("person_uname")
                    });
                    var t = wx.getStorageSync("personphone");
                    t == e.data ? wx.showModal({
                        title: "可以正常考勤",
                        content: "本机手机号" + t + "与绑定手机号" + e.data + "两者匹配，可以正常考勤",
                        showCancel: !1,
                        confirmText: "我已知晓",
                        success: function(e) {}
                    }) : wx.showModal({
                        title: "不能正常考勤",
                        content: "本机手机号" + t + "与绑定手机号" + e.data + "两者不匹配，进行考勤将会被视作代签",
                        showCancel: !1,
                        confirmText: "我已知晓",
                        success: function(e) {}
                    });
                }
            }
        });
    },
    getPhoneNumber: function(e) {
        console.log(e.detail.errMsg), console.log(e.detail.iv), console.log(e.detail.encryptedData);
        var a = this;
        wx.checkSession({
            success: function() {
                wx.request({
                    url: t.getInterfaceData() + "decodephone.action",
                    data: {
                        iv: e.detail.iv,
                        encryptedData: e.detail.encryptedData,
                        stunum: wx.getStorageSync("person_uname")
                    },
                    header: {
                        "content-type": "application/json"
                    },
                    success: function(e) {
                        if (console.log(e.data), a.setData({
                            hiddenmodalput: !a.data.hiddenmodalput,
                            sjsvalue: ""
                        }), console.log("xx" + e.data), "-1" != e.data) {
                            try {
                                wx.setStorageSync("personphone", e.data.phoneNumber);
                            } catch (e) {}
                            wx.showModal({
                                title: "绑定成功",
                                content: "您已经绑定成功，您的手机号" + e.data.phoneNumber + "已经与您的学号" + wx.getStorageSync("person_uname") + "绑定",
                                showCancel: !1,
                                confirmText: "我已知晓",
                                success: function(e) {
                                    try {
                                        wx.setStorageSync("personphone", e.data.phoneNumber);
                                    } catch (e) {}
                                }
                            });
                        } else wx.showModal({
                            title: "绑定失败",
                            content: "您的手机号已经被他人绑定",
                            showCancel: !1,
                            confirmText: "我已知晓",
                            success: function(e) {}
                        });
                    }
                });
            },
            fail: function() {
                wx.login({
                    success: function(n) {
                        n.code ? wx.request({
                            url: t.getInterfaceData() + "onkey.action",
                            data: {
                                code: n.code,
                                stunum: wx.getStorageSync("person_uname")
                            },
                            header: {
                                "content-type": "application/json"
                            },
                            success: function(n) {
                                wx.request({
                                    url: t.getInterfaceData() + "decodephone.action",
                                    data: {
                                        iv: e.detail.iv,
                                        encryptedData: e.detail.encryptedData,
                                        stunum: wx.getStorageSync("person_uname")
                                    },
                                    header: {
                                        "content-type": "application/json"
                                    },
                                    success: function(e) {
                                        if (console.log(e.data), a.setData({
                                            hiddenmodalput: !a.data.hiddenmodalput,
                                            sjsvalue: ""
                                        }), console.log("xx" + e.data), "-1" != e.data) {
                                            try {
                                                wx.setStorageSync("personphone", e.data.phoneNumber);
                                            } catch (e) {}
                                            wx.showModal({
                                                title: "绑定成功",
                                                content: "您已经绑定成功，您的手机号" + e.data.phoneNumber + "已经与您的学号" + wx.getStorageSync("person_uname") + "绑定",
                                                showCancel: !1,
                                                confirmText: "我已知晓",
                                                success: function(e) {
                                                    try {
                                                        wx.setStorageSync("personphone", e.data);
                                                    } catch (e) {}
                                                }
                                            });
                                        } else wx.showModal({
                                            title: "绑定失败",
                                            content: "您的手机号已经被他人绑定",
                                            showCancel: !1,
                                            confirmText: "我已知晓",
                                            success: function(e) {}
                                        });
                                    }
                                });
                            }
                        }) : console.log("登录失败！" + n.errMsg);
                    }
                });
            }
        });
    },
    getPhoneNumber1: function(e) {
        console.log(e.detail.errMsg), console.log(e.detail.iv), console.log(e.detail.encryptedData);
        var a = this;
        wx.checkSession({
            success: function() {
                wx.request({
                    url: t.getInterfaceData() + "rdecodephone.action",
                    data: {
                        iv: e.detail.iv,
                        encryptedData: e.detail.encryptedData,
                        stunum: wx.getStorageSync("person_uname")
                    },
                    header: {
                        "content-type": "application/json"
                    },
                    success: function(e) {
                        if (console.log(e.data), a.setData({
                            hiddenmodalput1: !a.data.hiddenmodalput1,
                            sjsvalue: ""
                        }), console.log("xx" + e.data), "-1" != e.data) {
                            try {
                                wx.setStorageSync("personphone", e.data);
                            } catch (e) {}
                            wx.showModal({
                                title: "刷新成功",
                                content: "本地手机号已被确定为" + e.data + "。",
                                showCancel: !1,
                                confirmText: "我已知晓",
                                success: function(e) {}
                            });
                        }
                    }
                });
            },
            fail: function() {
                wx.login({
                    success: function(n) {
                        n.code ? wx.request({
                            url: t.getInterfaceData() + "onkey.action",
                            data: {
                                code: n.code,
                                stunum: wx.getStorageSync("person_uname")
                            },
                            header: {
                                "content-type": "application/json"
                            },
                            success: function(n) {
                                wx.request({
                                    url: t.getInterfaceData() + "rdecodephone.action",
                                    data: {
                                        iv: e.detail.iv,
                                        encryptedData: e.detail.encryptedData,
                                        stunum: wx.getStorageSync("person_uname")
                                    },
                                    header: {
                                        "content-type": "application/json"
                                    },
                                    success: function(e) {
                                        console.log(e.data), a.setData({
                                            hiddenmodalput1: !a.data.hiddenmodalput1,
                                            sjsvalue: ""
                                        }), console.log("xx" + e.data);
                                        try {
                                            wx.setStorageSync("personphone", e.data);
                                        } catch (e) {}
                                        wx.showModal({
                                            title: "刷新成功",
                                            content: "本地手机号已被确定为" + e.data + "。",
                                            showCancel: !1,
                                            confirmText: "我已知晓",
                                            success: function(e) {}
                                        });
                                    }
                                });
                            }
                        }) : console.log("登录失败！" + n.errMsg);
                    }
                });
            }
        });
    },
    bindViewTap: function() {
        wx.navigateTo({
            url: "../logs/logs"
        });
    },
    onLoad: function() {
        var t = this;
        null == e.appData.userinfo ? wx.redirectTo({
            url: "../login/login"
        }) : (this.setData({
            username: e.appData.userinfo.username
        }), this.setData({
            person_uname: e.appData.userinfo.person_uname
        }), this.setData({
            username: e.appData.userinfo.username,
            person_uname: e.appData.userinfo.person_uname,
            type: wx.getStorageSync("persontype")
        })), e.globalData.userInfo ? this.setData({
            userInfo: e.globalData.userInfo,
            hasUserInfo: !0
        }) : this.data.canIUse ? e.userInfoReadyCallback = function(e) {
            t.setData({
                userInfo: e.userInfo,
                hasUserInfo: !0
            });
        } : wx.getUserInfo({
            success: function(a) {
                e.globalData.userInfo = a.userInfo, t.setData({
                    userInfo: a.userInfo,
                    hasUserInfo: !0
                });
            }
        });
        var a = wx.getUpdateManager();
        a.onCheckForUpdate(function(e) {
            console.log(1.6), console.log(e.hasUpdate);
        }), a.onUpdateReady(function() {
            wx.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启应用？",
                success: function(e) {
                    e.confirm && a.applyUpdate();
                }
            });
        }), a.onUpdateFailed(function() {});
    },
    onShow: function() {
        this.setData({
            modeTitle: "未点击考勤模式",
            myTitle: "未点击修改密码"
        });
        var e = wx.getUpdateManager();
        e.onCheckForUpdate(function(e) {
            console.log(1.6), console.log(e.hasUpdate);
        }), e.onUpdateReady(function() {
            wx.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启应用？",
                success: function(t) {
                    t.confirm && e.applyUpdate();
                }
            });
        }), e.onUpdateFailed(function() {});
    },
    getUserInfo: function(t) {
        console.log(t), e.globalData.userInfo = t.detail.userInfo, this.setData({
            userInfo: t.detail.userInfo,
            hasUserInfo: !0
        });
    },
    pwdBtnClick: function(e) {
        this.setData({
            myTitle: "修改密码"
        });
    },
    modeBtnClick: function(a) {
        this.setData({
            modeTitle: "考勤模式"
        });
        var n = this;
        wx.request({
            url: t.getInterfaceData() + "getMtype.action",
            data: {
                person_uname: e.appData.userinfo.person_uname
            },
            header: {
                "content-type": "application/json"
            },
            success: function(e) {
                1 == e.data ? n.setData({
                    modeType: e.data
                }) : 0 == e.data && n.setData({
                    modeType: e.data
                }), console.log(e.data);
            }
        });
    },
    cNumBtnClick: function() {
        var a = this;
        wx.request({
            url: t.getInterfaceData() + "setMtype.action",
            data: {
                p_num: e.appData.userinfo.person_uname,
                newMtype: 0
            },
            header: {
                "content-type": "application/json"
            },
            success: function(e) {
                a.setData({
                    modeType: 0,
                    modeTitle: "考勤模式修改完毕"
                }), wx.showModal({
                    title: "提示",
                    content: "当前考勤模式为：数字签到",
                    confirmText: "我已知晓",
                    showCancel: !1,
                    success: function(e) {
                        e.confirm && console.log("用户点击确定");
                    }
                }), console.log(e.data);
            }
        });
    },
    cScanBtnClick: function() {
        var a = this;
        wx.request({
            url: t.getInterfaceData() + "setMtype.action",
            data: {
                p_num: e.appData.userinfo.person_uname,
                newMtype: 1
            },
            header: {
                "content-type": "application/json"
            },
            success: function(e) {
                a.setData({
                    modeType: 1,
                    modeTitle: "考勤模式修改完毕"
                }), wx.showModal({
                    title: "提示",
                    content: "当前考勤模式为：扫码签到",
                    confirmText: "我已知晓",
                    showCancel: !1,
                    success: function(e) {
                        e.confirm && console.log("用户点击确定");
                    }
                }), console.log(e.data);
            }
        });
    },
    exitBtnClick: function(e) {
        try {
            wx.removeStorageSync("username"), wx.removeStorageSync("personid"), wx.removeStorageSync("person_uname"), 
            wx.removeStorageSync("userhistory"), wx.removeStorageSync("passhistory"), wx.removeStorageSync("persontype"), 
            wx.redirectTo({
                url: "../login/login"
            });
        } catch (e) {}
    },
    cpwdBtnClick: function() {
        var a = this;
        wx.request({
            url: t.getInterfaceData() + "updatepwd.action",
            data: {
                id: e.appData.userinfo.personid,
                password: this.data.newpassword
            },
            header: {
                "content-type": "application/json"
            },
            success: function(e) {
                console.log(e.data), 0 == e.data ? (wx.showToast({
                    icon: "loading",
                    title: "修改失败"
                }), a.setData({
                    myTitle: ""
                })) : (wx.showToast({
                    icon: "success",
                    title: "修改成功"
                }), a.setData({
                    myTitle: ""
                }));
            }
        });
    },
    cpasswordInput: function(e) {
        this.setData({
            newpassword: e.detail.value
        });
    }
});